<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

    <title> - 注册</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="__ROOT__/Public/Admin/css/bootstrap.min.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/style.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/login.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
	<style>
		span.help-block{color:red;}
		.tips{color:red;}
	</style>

</head>

<body>
	<div class="logo"></div>
	<div class="signin">
		<div class="signinpanel">
	        <div class="row">
	            <div class="col-sm-12">
	                <form class="js-ajax-forms" method="post" action="{:U('Admin/Public/register')}" style="padding-top:10px;">
						<div>
							<span class="input-border"></span>
							<input type="text" id="UserName" name="UserName" class="form-control uname" placeholder="用户名" />
						</div>
						<div>
							<span class="input-border"></span>
							<input type="text" id="Phone" name="Phone" class="form-control phone" placeholder="请输入手机号" />
						</div>
						<div>
							<span class="input-border"></span>
							<input type="password" id="Password" name="Password" class="form-control pword m-b" placeholder="6-16位数字或字母" />
						</div>
						<div>
							<span class="input-border"></span>
							<input type="password" id="ConfirmPassword" name="ConfirmPassword" class="form-control pword m-b" placeholder="再次输入密码" />
						</div>
						<div class="tips"></div>
							<button type="submit" class="btn btn-success btn-block">注册</button>
	                </form>
	            </div>
	        </div>
	    </div>
	</div>
	<div class="signup-footer">
        <div class="pull-left">
           <span class="copy-dot"></span> copyright &copy; 江苏科健教育软件有限公司 <span class="copy-dot"></span>
        </div>
    </div>
	<script src="__ROOT__/Public/Admin/js/jquery.min.js?v=2.1.4"></script>
	<script src="__ROOT__/Public/Admin/js/bootstrap.min.js?v=3.3.6"></script>
	<script type="text/javascript" src="__ROOT__/Public/Admin/js/ajaxForm.js"></script>
	<script src="__ROOT__/Public/Admin/js/plugins/validate/jquery.validate.min.js"></script>
	<script src="__ROOT__/Public/Admin/js/plugins/validate/messages_zh.min.js"></script>
<script>
	$(document).ready(function () {
		$.validator.setDefaults({
			highlight: function (element) {
				$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
			},
			success: function (element) {
				element.closest('.form-group').removeClass('has-error').addClass('has-success');
			},
			errorElement: "span",
			errorPlacement: function (error, element) {
				if (element.is(":radio") || element.is(":checkbox")) {
					error.appendTo(element.parent().parent().parent());
				} else {
					error.appendTo(element.parent());
				}
			},
			errorClass: "help-block m-b-none",
			validClass: "help-block m-b-none "
		});

		$.validator.addMethod("isPhone", function (value, element) {
			var phone = /^1[34578]\d{9}$/;
			return phone.test(value);
		}, "请输入正确的手机号码");

		var icon = "<i class='fa fa-times-circle'></i> ";
		var form = $('form.js-ajax-forms');
		var formloading = false;
		//表单验证开始
		form.validate({
			//验证规则
			rules: {
				UserName: {
					required: true,
				},
				Password: {
					required: true,
					minlength: 6,
					maxlength:16
				},
				ConfirmPassword: {
					required: true,
					minlength: 6,
					maxlength:16,
					equalTo: "#Password"
				},
				Phone: {
					isPhone: true,
					required: true
				}
			},
			//验证未通过提示消息
			messages: {
				UserName: {
					required: icon + "请输入用户名"
				},
				Password: {
					required: icon + "请输入密码",
					minlength: icon + "密码必须6个字符以上",
					maxlength: icon + "密码必须16个字符以下"
				},
				ConfirmPassword: {
					required: icon + "请再次输入密码",
					minlength: icon + "密码必须5个字符以上",
					maxlength: icon + "密码必须16个字符以下",
					equalTo: icon + "两次输入的密码不一致"
				},
				Phone: {
					required: icon + "请输入手机号码"
				}
			},
			//验证通过，提交表单
			submitHandler: function (forms) {
				if (formloading)
					return;
				$(forms).ajaxSubmit({
					url: form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
					dataType: 'json',
					beforeSubmit: function (arr, $form, options) {
						formloading = true;
					},
					success: function (data, statusText, xhr, $form) {
						console.log(JSON.stringify(data));
						formloading = false;
						if (data.status) {
							if(document.referrer){
								location.href = document.referrer;
							}else{
								location.href = '/';
							}

						} else {
							$('.tips').html(data.info);
							$('.tips').show();
						}
					}
				});
			}
		});

		$('input').focus(function(){
			$('.tips').hide();
			$('.tips').html('');
		});
	});
</script>
</body>
</html>
